package com.asset.troubleticket.dao;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.asset.troubleticket.domain.Ticket;
@Repository
public class TicketDao {
	@Autowired
	SessionFactory sessionFactory;
	
	
	public void addTicket(Ticket ticket){
		try{
			sessionFactory.getCurrentSession().save(ticket);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	
	public void editTicket(Ticket ticket){
		try{
			sessionFactory.getCurrentSession().saveOrUpdate(ticket);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	public void deleteTicket(Ticket ticket){
		try{
			sessionFactory.getCurrentSession().delete(ticket);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	public Ticket getById(Integer id){
		try{
		return (Ticket)	sessionFactory.getCurrentSession().load(TicketDao.class,id);
			}catch(Exception ex){
				ex.printStackTrace();
				return null;
			}
	}
}
